section .text
   global _start         ;必须声明才能使用 gcc
_start:                  ;告诉链接器入口点
   mov  eax, 45          ;sys_brk
   xor  ebx, ebx
   int  80h              ; 这一步执行的是sys_brk(0),即获取到当前的堆的尾地址，保存在eax中。
   add  eax, 16384       ; eax += 16384，即堆增长16KB。
   mov  ebx, eax
   mov  eax, 45          ;sys_brk
   int  80h
   cmp  eax, 0
   jl   exit             ;exit, if error
   mov  edi, eax         ;EDI = highest available address
   sub  edi, 4           ;pointing to the last DWORD
   mov  ecx, 4096        ;number of DWORDs allocated
   xor  eax, eax         ;clear eax
   std                   ;backward
   rep  stosd            ;repete for entire allocated area
   cld                   ;put DF flag to normal state
   mov  eax, 4
   mov  ebx, 1
   mov  ecx, msg
   mov  edx, len
   int  80h              ;打印消息
exit:
   mov  eax, 1
   xor  ebx, ebx
   int  80h
section .data
msg     db      "Allocated 16 kb of memory!", 10
len     equ     $ - msg